package com.datamation.swadeshi.control.data;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;


import com.datamation.swadeshi.model.FTranIss;

public class FTranIssDS {
	private SQLiteDatabase dB;
	private DatabaseHelper dbHelper;
	Context context;
	private String TAG="swadeshi";
	
	
	public FTranIssDS (Context context)
	{
		this.context = context;
		dbHelper = new DatabaseHelper(context);
	}
	
	public void open() throws SQLException 
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	
	
	@SuppressWarnings("static-access")
	public int createOrUpdateFreeSlab(ArrayList<FTranIss>  list) 
	{
		
		int serverdbID =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		Cursor cursor = null;
		
	try{
		
			
			
    for (FTranIss ftraniss : list) 
    {
		
			ContentValues values = new ContentValues();
			
			values.put(dbHelper.FTRANISS_ID, ftraniss.getFTRANISS_ID());
			values.put(dbHelper.FTRANISS_REFNO, ftraniss.getFTRANISS_REFNO());
			values.put(dbHelper.FTRANISS_TXNDATE, ftraniss.getFTRANISS_TXNDATE());
			values.put(dbHelper.FTRANISS_STKRECNO, ftraniss.getFTRANISS_STKRECNO());
			values.put(dbHelper.FTRANISS_STKRECDATE, ftraniss.getFTRANISS_STKRECDATE());
			values.put(dbHelper.FTRANISS_STKTXNDATE, ftraniss.getFTRANISS_STKTXNDATE());
			values.put(dbHelper.FTRANISS_STKTXNTYPE, ftraniss.getFTRANISS_STKTXNTYPE());
			values.put(dbHelper.FTRANISS_LOCCODE, ftraniss.getFTRANISS_LOCCODE());
			values.put(dbHelper.FTRANISS_ITEMCODE, ftraniss.getFTRANISS_ITEMCODE());
			values.put(dbHelper.FTRANISS_QTY, ftraniss.getFTRANISS_QTY());
			values.put(dbHelper.FTRANISS_COSTPRICE, ftraniss.getFTRANISS_COSTPRICE());
			values.put(dbHelper.FTRANISS_AMT, ftraniss.getFTRANISS_AMT());
			values.put(dbHelper.FTRANISS_OTHCOST, ftraniss.getFTRANISS_OTHCOST());
			
			serverdbID = (int) dB.insert(dbHelper.TABLE_FTRANDET, null, values);

			}
		}catch (Exception e) {
		
			Log.v("Exception", e.toString());
	
		}finally {  
			if (cursor !=null) {
				cursor.close();
			}
			dB.close();
		}
		return serverdbID;
				
	}
}
